#!/bin/bash

PROJECTNAME="ra_local_tcpws"

# DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DIR="/usr/local/rongan/bin"/${PROJECTNAME}
echo $DIR


auxnum=$(ps -aux |grep "ra_local_tcpws -c" |grep -v grep  |wc -l)
#echo "$auxnum"

if [ "$auxnum" != "0" ]; then 
    bash ${DIR}/stop_tcpws.sh

    auxnum=$(ps -aux |grep "ra_local_tcpws -c" |grep -v grep  |wc -l)

    if [ "$auxnum" != "0" ]; then 
       echo "tcpws stop fail!"
    fi
fi

if [ "$1" != "-c" ]; then
    echo "The two strings are the same"
    exit 1
fi

if [ -f "$2" ]; then
	nohup ${DIR}/${PROJECTNAME} -c $2 >/dev/null 2>&1 &

    auxnum=$(ps -aux |grep "ra_local_tcpws -c" |grep -v grep  |wc -l)
    echo "$auxnum"
    
    if [ "$auxnum" == "0" ]; then 
    	echo "tcpws fail"
        exit 1
    fi
    echo "$(date +%Y-%m-%d\ %H:%M:%S):tcpws server start"
else
    echo "File \"$2\" not exists"
    exit 1
fi

exit 0
